package zhjb.platform.web.module.system.action;

import javax.servlet.http.HttpSession;

import zhjb.platform.core.AppContext;
import zhjb.platform.util.SpringUtil;
import zhjb.platform.web.BaseAction;
import zhjb.platform.web.module.system.bean.User;
import zhjb.platform.web.module.system.service.UserService;

import com.opensymphony.xwork2.Action;

public class LoginAction extends BaseAction {
	private UserService userService = (UserService) SpringUtil.getWebApplicationContext().getBean("userService");
	private String userName;
	private String password;

	public String login() {
		User user = userService.login(userName, password);
		if (user == null) {
			return Action.INPUT;
		} else {
			HttpSession session = request.getSession(true);
			AppContext.addMessage(session.getId() + "");
			session.setAttribute("user", user);
			request.setAttribute("user", user);
		}
		return Action.SUCCESS;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

}
